package com.dq.vod.controller;

import com.dq.commonutils.pojo.DqException;
import com.dq.commonutils.vo.Result;
import com.dq.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @project: guli_parent
 * @ClassName: VodController
 * @author: dq
 * @creat: 2022/7/29 19:31
 */
@RestController
@RequestMapping("eduvod/video")
// @CrossOrigin
public class VodController {

    @Autowired
    private VodService vodService;

    /**
     * 上传视频到阿里云
     * @return
     */
    @PostMapping("uploadAliyunVideo")
    public Result uploadAliyunVideo(MultipartFile file){
        String videoId = vodService.uploadAliyunVideo(file);
        return Result.success(videoId);
    }

    /**
     * 单独删除一个小节
     * @param videoSourceId
     * @return
     */
    @PostMapping("deleteAliyunViedo/{videoSourceId}")
    public Result deleteAliyunViedo(@PathVariable String videoSourceId){
        vodService.deleteAliyunViedoByVedioId(videoSourceId);
        return  Result.success("删除成功");
    }

    /**
     * 删除多个小节视频
     * @param videoIdList
     * @return
     */
    @PostMapping("deleteAliyunVideoBatch")
    public Result deleteAliyunVideoBatch(@RequestParam("videoIdList") List<String> videoIdList){
        vodService.deleteAliyunVideoBatch(videoIdList);
        return  Result.success(null);
    }

    /**
     * 获取视频凭证
     * @param id
     * @return
     */
    @GetMapping("getPlayAuth/{id}")
    public Result getPlayAuth(@PathVariable("id") String id){
        if (StringUtils.isEmpty(id)){
            throw new DqException(20001,"此视频id不存在");
        }
        String playAuth = vodService.getPlayAuth(id);
        Map<String, String> map = new HashMap<>();
        map.put("playAuth",playAuth);
        return Result.success(map);
    }
}
